<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('memory_limit', '1000M');
set_time_limit(0);
CONST TYPE_NORMAL = 1;
CONST TYPE_BAD = 2;
include_once('function.php');
include_once('sell.php');
include_once('rent.php');
$borough_file_name = 'borough';
$borough_file=file($borough_file_name);
#$subwaytoborough_filename = 'subwaytoborough';
#$subwaytoborough_file = file($subwaytoborough_filename);

function outputBadHouse($house_info, $bad_type){
    $house_info['bad_type'] = $bad_type;
    $out = json_encode($house_info);
    echo ' '."\t".$out."#B\n";
}
$borough = array();
foreach($borough_file as &$line_json){
    $line = json_decode($line_json, True);
    $borough[$line['borough_name']] = 
	array('id'=>$line['id'], 'cityarea_id'=>$line['cityarea_id'], 'cityarea2_id'=>$line['cityarea2_id']);
}
#foreach($subwaytoborough_file as &$line_json){
#    $line = json_decode($line_json, True);
#    $subwaytoborough[$line['bid']] = $line['id'];
#}
while (($line_json = fgets(STDIN)) !== false) {
    $line_json = trim($line_json);
    if(empty($line_json))
        continue;
    $house_info = json_decode($line_json, true);
    #$house_info['tag'] = str_replace("12#", "", $house_info['tag']);
    #$is_subway = $subwaytoborough[$house_info['borough_id']];
    #if(!empty($is_subway)){
    #    $house_info['tag'] = $house_info['tag'].'12#';
    #}  
    
    //处理小区
    $house_info['borough_name']=trim($house_info['borough_name']);
    if ($borough[$house_info['borough_name']]){
	    $house_info['borough_id'] = $borough[$house_info['borough_name']]['id'];
        $house_info['cityarea_id'] = $borough[$house_info['borough_name']]['cityarea_id'];
        $house_info['cityarea2_id'] = $borough[$house_info['borough_name']]['cityarea2_id'];
    }
    else{
	    outputBadHouse($house_info, 19);
	    continue;
    }
    $out = json_encode($house_info);
    echo ' '."\t".$out."#N\n";
}
    

    
